package com.google.android.apps.wakemewhere;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlarmListAdapter extends CursorAdapter {

	private Cursor mCursor;
	private Context mContext;
	private final LayoutInflater mInflater;

	public AlarmListAdapter(Context context, Cursor cursor) {
		super(context, cursor, true);
		mInflater = LayoutInflater.from(context);
		mContext = context;
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		Alarm alarm = new Alarm(cursor);

		CheckBox cb = (CheckBox) view.findViewById(R.id.clock_onoff);
		if (alarm.isEnabled()) {
			cb.setBackgroundResource(R.drawable.fromdeskclock_ic_clock_alarm_on);
		} else {
			cb.setBackgroundResource(R.drawable.fromdeskclock_ic_clock_alarm_off);
		}
		ImageView bar = (ImageView) view.findViewById(R.id.bar_onoff);
		if (alarm.isEnabled()) {
			bar.setImageResource(R.drawable.fromdeskclock_ic_indicator_on);
		} else {
			bar.setImageResource(R.drawable.fromdeskclock_ic_indicator_off);
		}
		TextView tv_top = (TextView) view.findViewById(R.id.toptext);
		tv_top.setText(alarm.getLabel());

		TextView tv_bottom = (TextView) view.findViewById(R.id.bottomtext);
		tv_bottom.setText(alarm.getLocationSummary());

	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		final View view = mInflater.inflate(R.layout.row, parent, false);
		return view;
	}

}
